/**
 * vee-validate项目地址
 * http://vee-validate.logaretm.com/index.html#about
 */
// 加载vee-validate下面本地化文件zh_CN（中文提示信息），默认是加载en（英文提示信息）
import zhCN from 'vee-validate/dist/locale/zh_CN'
import VeeValidate, {
  Validator
} from 'vee-validate'
import rules from './rules'
// 添加一个本地化文件
Validator.addLocale(zhCN)

const Veeconfig = {
  locale: 'zh_CN'
}
const dictionary = {
  zh_CN: {
    messages: {
      required: field => '您的' + field + '还未填写',
      specialchar: field => `${field}不能包含特殊字符`,
      confirmed: (field, field2) => '两次输入的密码不一致',
      max_str: (field, [target]) => `${field}必须小于${target}`,
      min_str: (field, [target]) => `${field}必须大于${target}`,
      price: (field, [target = 2]) => `${field}必须是大于0的数字，且最多${target}位小数`,
      price_have_zero: (field, [target = 2]) => `${field}必须是大于等于0的数字，且最多${target}位小数`,
      numeric: (field) => ` ${field} 必须是数字`,
      int: field => ` ${field} 必须是整数`,
      plus: field => ` ${field} 必须是大于0的数字`,
      requireddesc: field => '可以写一段文字来描述您的商品，或其他您想表达的内容',
      requiredchoose: field => `您还没有选择${field}`
    },
    attributes: {
      email: '邮箱',
      password: '密码',
      phone: '手机号',
      mobile: '手机号',
      telephone: '联系方式',
      specialchar: '特殊字符'
    }
  }
}
// 添加自定义规则
rules.rules.map(function (item) {
  Validator.extend(item.name, item.validator)
})
Validator.updateDictionary(dictionary)
export default {
  install: function (Vue, Option) {
    Vue.use(VeeValidate, Veeconfig)
  }
}
